import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter_common_app/data/recommend_playlist_data.dart';
import 'package:flutter_common_app/router/routes.dart';

class RouteUtil {
  static toPlaylistDetailPage(
      RecommendPlaylistData recommendPlaylistData, BuildContext context) {
    Routes.navigateTo(context, Routes.playlistDetailPage, params: {
      'data': jsonEncode(recommendPlaylistData.toJson()),
    });
  }

  static toPlayDetailPage(BuildContext context) {
    Routes.navigateTo(context, Routes.playingDetailPage);
  }

  static commonNavigateTo(BuildContext context, String path) {
    if (path.contains('page=')) {
      String pagePath = path.substring(path.lastIndexOf('/'));
      Routes.navigateTo(context, pagePath);
    }
  }

  static toWebViewPage(BuildContext context, String url) {
    Routes.navigateTo(
      context,
      Routes.webViewPage,
      params: {'url': url},
    );
  }
}
